<!--拌和站---拌合站设置-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-06 13:13:25
 * @LastEditors: CNN 969682281@qq.com
 * @LastEditTime: 2023-09-07 09:29:05
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="mixingPlant">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div></div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>

      <!-- <tree :treeData="treeData" :checkData="checkData" name="currencyList" nodeKey="fCompanyid"
                                                                @getTreeInfo="handleNodeClick" :defaultProps="defaultProps">
                                                            </tree> -->
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left"></div>
        <!-- 顶部按钮 -->
        <div class="print" style="justify-content: flex-end">
          <!-- v-if="nature == '建设单位'" -->
          <el-button
            type="primary"
            v-if="yj_save"
            icon="el-icon-check"
            size="small"
            @click="yj_saveForm"
            >保存
          </el-button>
        </div>
      </div>
      <!-- 表格 -->
      <div class="text_table editTableAlarm">
        <tableData
          :config="table_config"
          :currentRow="false"
          :dataList="tableData"
          :loading="listLoading"
          @inputValue="inputValue"
          statusType="1"
        />
      </div>
    </div>
  </div>
</template>
<script>
import tree from "@/components/public/el-trees"; //左侧机构树
import TableData from "@/components/public/el-tables";
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
// import publicForm from "@/components/public/el-form.vue"
import {
  getUserCompanyTreeList, //树状图接口
  saveStationWarn, // 查询-拌合站预警信息-新增接口
  getStationWarnByCompanyId, // 查询-拌合站预警信息-详情接口
} from "@/api/request.js";
import { statusType2 } from "@/utils/config"; //配置项
export default {
  name: "alarmParameterSetting",
  data() {
    return {
      name: "alarmParameterSetting", //按钮配置页面代号
      nature: null,
      yj_save: null,
      formData: {}, //新增编辑向后台传递对象

      // 拌和站列表配置项
      table_config: {
        classCell: true,
        thead: [
          {
            label: "",
            prop: "name",
            minWidth: "35px",
            filter: true,
            btn: true,
            align: "center",
            colorName: "",
            callback: (rowData) => {
              let data = statusType2[rowData.name];
              if (data) {
                return data.label;
              }
            },
            specialClass: (rowData) => {
              let data = statusType2[rowData.name];
              if (data) {
                return data.className;
              }
            },
          },
          {
            label: "水(%)",
            prop: "water",
            minWidth: "35px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "水泥(%)",
            prop: "cement",
            minWidth: "35px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },

          {
            label: "骨料(%)",
            prop: "aggregate",
            minWidth: "35px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "粉煤灰(%)",
            prop: "flyash",
            minWidth: "35px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "矿粉(%)",
            prop: "oredesign",
            minWidth: "35px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "外加剂(%)",
            prop: "admixture",
            minWidth: "35px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "闭合流程",
            prop: "examine",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            align: "center",
            options: [
              {
                value: "无需闭合",
                label: "无需闭合",
              },
              {
                value: "一级流程",
                label: "一级流程",
              },
              {
                value: "二级流程",
                label: "二级流程",
              },
              {
                value: "三级流程",
                label: "三级流程",
              },
              {
                value: "四级流程",
                label: "四级流程",
              },
              {
                value: "五级流程",
                label: "五级流程",
              },
            ],
          },
          {
            label: "一级审核",
            prop: "examine0",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            options: [],
            align: "center",
          },
          {
            label: "二级审核",
            prop: "examine1",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            options: [],
            align: "center",
          },
          {
            label: "三级审核",
            prop: "examine2",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            options: [],
            align: "center",
          },
          {
            label: "四级审核",
            prop: "examine3",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            options: [],
            align: "center",
          },
          {
            label: "五级审核",
            prop: "examine4",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            options: [],
            align: "center",
          },
        ],
        isCheckBox: false,
        isIndex: false,
        isOperation: true,
      },
      tableData: [], //表格列表数据列表
      fAduitUser1List: [], //一级审核拼接
      fAduitUser2List: [], //一级审核拼接
      fAduitUser3List: [], //一级审核拼接
      fAduitUser4List: [], //一级审核拼接
      fAduitUser5List: [], //一级审核拼接
      detailData: {}, //拌合站预警信息-详情
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级
      showName: "未选择公司",
      dialogHeight: "330px", //新增编辑弹框高度
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      // 列表给后端传参
      getList: {
        companyId: "", // 施工标段id
      },

      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据

      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      userInfo: {}, //登录用户
      checkData: [],
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
      fNatureList: null, //机构性质
      jgxzList: {
        value: "",
        label: "",
      }, //机构性质赋值
    };
  },
  components: {
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    // publicForm,//弹框表格
  },
  created() {
    // 获取机构性质  一级审核至五级审核下拉框内容
    this.fNatureList = JSON.parse(
      window.sessionStorage.getItem("CompanyNature")
    );
    let listOption = [
      {
        value: "==请选择==",
        label: "==请选择==",
      },
    ];
    this.jgxzList = {
      value: "",
      label: "",
    };
    for (let index = 0; index < this.fNatureList.length; index++) {
      const element = this.fNatureList[index];
      this.jgxzList = {
        value: element.fItemValue,
        label: element.fItemName,
      };
      listOption.push(this.jgxzList);
    }

    for (let index = 8; index < this.table_config.thead.length; index++) {
      const element = this.table_config.thead[index];
      element.options = listOption;
    }

    // 获取机构性质  一级审核至五级审核下拉框内容
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
    if (JSON.parse(sessionStorage.getItem("treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_save = btnStr.includes("yj_save");
      } else {
        this.yj_save = true;
      }
    },
    // 点击列表当前行，获取当前信息
    rowChange(row) {
      this.fId = row.fId;
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "1", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);

            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            // this.showName = this.treeData[0].fShortname;//当前点击组织机构名称
            // this.getList.companyId = this.treeData[0].fCompanyid;//当前点击组织机构ID
            // this.nature = this.treeData[0].fNature

            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("treeCheck")
              ).fShortname;

              this.getList.companyId = this.checkData[0];
              // this.nature = this.treeData[0].fNature
            } else {
              // this.nature = this.treeData[0].fNature
              this.checkData[0] = this.treeData[0].fCompanyid;

              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }

            // if (this.treeData[0].fNature == '建设单位') {

            this.yj_searchForm(this.getList); // 调用主页面列表接口
            // }
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.companyId = data.fCompanyid;
      this.nature = data.fNature;

      // if (data.fNature == '建设单位') {
      this.yj_searchForm(this.getList);
      // } else {
      //     this.tableData = []
      // }
    },

    // 获取列表数据
    yj_searchForm(data) {
      this.listLoading = true;
      getStationWarnByCompanyId(data)
        .then((res) => {
          if (res.errcode == 0) {
            var that = this;
            that.listLoading = false;
            var list = res.data.yjQmpMsStationwarn;
            this.formData = list;
            this.detailData = res.data.yjQmpMsStationwarn;
            var newfAduitUser1List = list.fAduitUser1.split("-");
            var newfAduitUser2List = list.fAduitUser2.split("-");
            var newfAduitUser3List = list.fAduitUser3.split("-");
            var newfAduitUser4List = list.fAduitUser4.split("-");
            var newfAduitUser5List = list.fAduitUser5.split("-");
            this.fAduitUser1List = [
              newfAduitUser1List[0],
              newfAduitUser1List[1],
              newfAduitUser1List[2],
              newfAduitUser1List[3],
              newfAduitUser1List[4],
            ];
            this.fAduitUser2List = [
              newfAduitUser2List[0],
              newfAduitUser2List[1],
              newfAduitUser2List[2],
              newfAduitUser2List[3],
              newfAduitUser2List[4],
            ];

            this.fAduitUser3List = [
              newfAduitUser3List[0],
              newfAduitUser3List[1],
              newfAduitUser3List[2],
              newfAduitUser3List[3],
              newfAduitUser3List[4],
            ];
            this.fAduitUser4List = [
              newfAduitUser4List[0],
              newfAduitUser4List[1],
              newfAduitUser4List[2],
              newfAduitUser4List[3],
              newfAduitUser4List[4],
            ];
            this.fAduitUser5List = [
              newfAduitUser5List[0],
              newfAduitUser5List[1],
              newfAduitUser5List[2],
              newfAduitUser5List[3],
              newfAduitUser5List[4],
            ];

            this.tableData = [
              {
                name: "1",
                water: list.fWaterwarn1, //水
                cement: list.fCementwarn1, //水泥
                aggregate: list.fAggregatewarn1, //骨料(%)
                flyash: list.fFlyashwarn1, //粉煤灰
                oredesign: list.fGgbswarn1, //矿粉
                admixture: list.fAdmixture1, //外加剂
                examine: list.fExamine1, //闭合流程
                examine0: this.fAduitUser1List[0], //一级审核
                examine1: this.fAduitUser1List[1], //二级审核
                examine2: this.fAduitUser1List[2], //三级审核
                examine3: this.fAduitUser1List[3], //四级审核
                examine4: this.fAduitUser1List[4], //五级审核
              },
              {
                name: "2",
                water: list.fWaterwarn2, //水
                cement: list.fCementwarn2, //水泥
                aggregate: list.fAggregatewarn2, //骨料(%)
                flyash: list.fFlyashwarn2, //粉煤灰
                oredesign: list.fGgbswarn2, //矿粉
                admixture: list.fAdmixture2, //外加剂
                examine: list.fExamine2, //闭合流程
                examine0: this.fAduitUser2List[0], //一级审核
                examine1: this.fAduitUser2List[1], //二级审核
                examine2: this.fAduitUser2List[2], //三级审核
                examine3: this.fAduitUser2List[3], //四级审核
                examine4: this.fAduitUser2List[4], //五级审核
              },
              {
                name: "3",
                water: list.fWaterwarn3, //水
                cement: list.fCementwarn3, //水泥
                aggregate: list.fAggregatewarn3, //骨料(%)
                flyash: list.fFlyashwarn3, //粉煤灰
                oredesign: list.fGgbswarn3, //矿粉
                admixture: list.fAdmixture3, //外加剂
                examine: list.fExamine3, //闭合流程
                examine0: this.fAduitUser3List[0], //一级审核
                examine1: this.fAduitUser3List[1], //二级审核
                examine2: this.fAduitUser3List[2], //三级审核
                examine3: this.fAduitUser3List[3], //四级审核
                examine4: this.fAduitUser3List[4], //五级审核
              },
              {
                name: "4",
                water: list.fWaterwarn4, //水
                cement: list.fCementwarn4, //水泥
                aggregate: list.fAggregatewarn4, //骨料(%)
                flyash: list.fFlyashwarn4, //粉煤灰
                oredesign: list.fGgbswarn4, //矿粉
                admixture: list.fAdmixture4, //外加剂
                examine: list.fExamine4, //闭合流程
                examine0: this.fAduitUser4List[0], //一级审核
                examine1: this.fAduitUser4List[1], //二级审核
                examine2: this.fAduitUser4List[2], //三级审核
                examine3: this.fAduitUser4List[3], //四级审核
                examine4: this.fAduitUser4List[4], //五级审核
              },
              {
                name: "5",
                water: list.fWaterwarn5, //水
                cement: list.fCementwarn5, //水泥
                aggregate: list.fAggregatewarn5, //骨料(%)
                flyash: list.fFlyashwarn5, //粉煤灰
                oredesign: list.fGgbswarn5, //矿粉
                admixture: list.fAdmixture5, //外加剂
                examine: list.fExamine5, //闭合流程
                examine0: this.fAduitUser5List[0], //一级审核
                examine1: this.fAduitUser5List[1], //二级审核
                examine2: this.fAduitUser5List[2], //三级审核
                examine3: this.fAduitUser5List[3], //四级审核
                examine4: this.fAduitUser5List[4], //五级审核
              },
            ];
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },

    // 保存接口
    yj_saveForm() {
      console.log("保存", this.formData);
      saveStationWarn(this.formData)
        .then((res) => {
          if (res.errcode == 0) {
            this.yj_searchForm(this.getList);
            this.$message.success("保存成功");
          } else {
            this.$message.error(res.msg);
            console.log("接口报错");
          }
        })
        .catch((error) => {
          console.log("报警参数设置-新增）", error);
        });
    },

    // 关闭新增编辑弹框
    resetForm() {
      this.dialogEditVisible = false;
    },
    // 类型改变时触发
    changeRadio(num) {
      if (num == 0) {
        this.formObj[1].disabled = true;
        this.formObj[1].rules[0].required = false;
      } else {
        this.formObj[1].disabled = false;
        this.formObj[1].rules[0].required = true;
      }
    },
    // 拌合站下拉框
    selectChange(value) {
      this.formData.fStationid = value.value; // 拌合站id
      this.formData.fStationname = value.label; // 拌合站名称
    },
    // 骨料详情
    inputValue(val, table) {
      // console.log("inputValue", val, table);
      for (let index = 0; index < table.length; index++) {
        const element = table[index];
        if (element.examine0 == "==请选择==") {
          element.examine0 = "";
        } else if (element.examine1 == "==请选择==") {
          element.examine1 = "";
        } else if (element.examine2 == "==请选择==") {
          element.examine2 = "";
        } else if (element.examine3 == "==请选择==") {
          element.examine3 = "";
        } else if (element.examine4 == "==请选择==") {
          element.examine4 = "";
        }
      }

      this.formData = {
        fId: this.detailData.fId, // 主键id
        fCompanyid: this.getList.companyId, // 施工单位id
        fCompanyname: this.showName, //施工单位
        fWaterwarn1: table[0].water, // 水(%) 低预警
        fWaterwarn2: table[1].water, // 水(%) 中预警
        fWaterwarn3: table[2].water, // 水(%) 高预警
        fWaterwarn4: table[3].water, // 水(%) 高预警
        fWaterwarn5: table[4].water, // 水(%) 高预警
        fCementwarn1: table[0].cement, // 水泥(%) 低预警
        fCementwarn2: table[1].cement, // 水泥(%) 中预警
        fCementwarn3: table[2].cement, // 水泥(%) 高预警
        fCementwarn4: table[3].cement, // 水泥(%) 高预警
        fCementwarn5: table[4].cement, // 水泥(%) 高预警
        fAggregatewarn1: table[0].aggregate, // 粗细骨料(%) 低预警
        fAggregatewarn2: table[1].aggregate, // 粗细骨料(%) 中预警
        fAggregatewarn3: table[2].aggregate, // 粗细骨料(%) 高预警
        fAggregatewarn4: table[3].aggregate, // 粗细骨料(%) 高预警
        fAggregatewarn5: table[4].aggregate, // 粗细骨料(%) 高预警
        fFlyashwarn1: table[0].flyash, // 粉煤灰(%) 低预警
        fFlyashwarn2: table[1].flyash, // 粉煤灰(%) 中预警
        fFlyashwarn3: table[2].flyash, // 粉煤灰(%) 高预警
        fFlyashwarn4: table[3].flyash, // 粉煤灰(%) 高预警
        fFlyashwarn5: table[4].flyash, // 粉煤灰(%) 高预警
        fGgbswarn1: table[0].oredesign, // 矿粉(%) 低预警
        fGgbswarn2: table[1].oredesign, // 矿粉(%) 中预警
        fGgbswarn3: table[2].oredesign, // 矿粉(%) 高预警
        fGgbswarn4: table[3].oredesign, // 矿粉(%) 高预警
        fGgbswarn5: table[4].oredesign, // 矿粉(%) 高预警
        fAdmixture1: table[0].admixture, // 外加剂(%) 低预警
        fAdmixture2: table[1].admixture, // 外加剂(%) 中预警
        fAdmixture3: table[2].admixture, // 外加剂(%) 高预警
        fAdmixture4: table[3].admixture, // 外加剂(%) 高预警
        fAdmixture5: table[4].admixture, // 外加剂(%) 高预警
        fExamine1: table[0].examine, // 闭合流程 低预警
        fExamine2: table[1].examine, // 闭合流程 中预警
        fExamine3: table[2].examine, // 闭合流程 高预警
        fExamine4: table[3].examine, // 闭合流程 高预警
        fExamine5: table[4].examine, // 闭合流程 高预警
        fAduitUser1:
          table[0].examine0 +
          "-" +
          table[0].examine1 +
          "-" +
          table[0].examine2 +
          "-" +
          table[0].examine3 +
          "-" +
          table[0].examine4, // 审核流程 一級预警
        fAduitUser2:
          table[1].examine0 +
          "-" +
          table[1].examine1 +
          "-" +
          table[1].examine2 +
          "-" +
          table[1].examine3 +
          "-" +
          table[1].examine4, // 审核流程 二級预警
        fAduitUser3:
          table[2].examine0 +
          "-" +
          table[2].examine1 +
          "-" +
          table[2].examine2 +
          "-" +
          table[2].examine3 +
          "-" +
          table[2].examine4, // 审核流程 三級预警
        fAduitUser4:
          table[3].examine0 +
          "-" +
          table[3].examine1 +
          "-" +
          table[3].examine2 +
          "-" +
          table[3].examine3 +
          "-" +
          table[3].examine4, // 审核流程 四級预警
        fAduitUser5:
          table[4].examine0 +
          "-" +
          table[4].examine1 +
          "-" +
          table[4].examine2 +
          "-" +
          table[4].examine3 +
          "-" +
          table[4].examine4, // 审核流程 五級预警
      };
    },
    // classCell(row, column, rowIndex, columnIndex) {
    //     console.log(row, column, rowIndex, columnIndex);
    //     if (rowIndex == 0 && columnIndex == 0) {

    //         return 'blueClass';
    //     } else if (rowIndex == 1 && columnIndex == 0) {

    //         return 'orangeClass';
    //     } else if (rowIndex == 2 && columnIndex == 0) {

    //         return 'redClass';
    //     }
    // },
    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
    // 点击设备编码
    openDialog(row) {
      this.fId = row.F_Id;
      this.editText(this.fId);
    },
  },
};
</script>
  
<style scoped>
.printTables {
  background: #fff;
  display: flex;
  justify-content: end;
  padding: 5px;
  margin-top: 10px;
}

.dialogBody {
  padding: 3px 20px;
  height: 80%;
  overflow-y: auto;
}

.baseTitle {
  /* border: 1px solid #0c204d; */
  border-bottom: 1px solid #0c204d;

  height: 30px;
  line-height: 30px;
  position: relative;
  padding-left: 15px;
}

.baseTitle::after {
  display: block;
  content: "";
  height: 30px;
  width: 5px;
  position: absolute;
  left: 0;
  top: 0;
  background: #0c204d;
}
</style>